﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RCREEE.Library.Entities;
using System.Data;

namespace RCREEE.Web
{
    public partial class ApprovedIncentives : System.Web.UI.Page
    {
        RCREEE.Library.Entities.ApprovedIncentives App = new Library.Entities.ApprovedIncentives();
        List<RCREEE.Library.Entities.ApprovedIncentives> Applist = new List<Library.Entities.ApprovedIncentives>();
        Project project = new Project();
        int[] LanguageCode = { 1033,1025, 1036 };
        int Key = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Session["LanguagCode"] != null)
            //    Session.Add("LanguagCode", "1033");
            if(!Page.IsPostBack)
            {
            #region CountriesDD
            try
            {


                //CountryDDL.DataSource = project.GetCountries(Convert.ToInt32(Session["LanguageCode"]));
                //CountryDDL.DataTextField = "Name";
                //CountryDDL.DataValueField = "ID";
                //CountryDDL.DataBind();

            }
            catch (Exception) { }
            #endregion
            if (Request["C"] != null)
                Key = Convert.ToInt32(Request["C"]);
            else
                if (Session["CountryId"] != null)
                    Key = Convert.ToInt32(Session["CountryId"]);

            if (Key != 0)
            {
                CountryDDL.SelectedValue = Key.ToString();
                MasterGrid.DataBind();
            }
            }
            if (CountryDDL.SelectedValue != "0")
            {
                FormView1.Visible = true;
                MasterGrid.DataBind();
            }
            else
                FormView1.Visible = false;
        }

        protected void Save_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                Applist.Add(new Library.Entities.ApprovedIncentives());
                Applist[i].Ceiling = ((System.Web.UI.WebControls.TextBox)FormView1.FindControl("Ceiling" + i)).Text;
                Applist[i].LanguageCode = LanguageCode[i];
                if (((System.Web.UI.WebControls.TextBox)FormView1.FindControl("Percentagetb")).Text !="")
                Applist[i].Percentage = Convert.ToInt32(((System.Web.UI.WebControls.TextBox)FormView1.FindControl("Percentagetb")).Text);
               
                if (((HiddenField)FormView1.FindControl("ApprovalId")).Value != "")
                    Applist[i].ApprovedIncentiveId = Convert.ToInt32(((HiddenField)FormView1.FindControl("ApprovalId")).Value);
                else
                    Applist[i].ApprovedIncentiveId = 0;
                Applist[i].ItemId = Convert.ToInt32(((HiddenField)FormView1.FindControl("ItemId")).Value);
                Applist[i].IncentiveId = Convert.ToInt32(((HiddenField)FormView1.FindControl("Incentive")).Value);
                Applist[i].CountryId = Convert.ToInt32(CountryDDL.SelectedValue);
            }
            App.UpdateApprovedIncentives(Applist);
        //UpdatePanel2.DataBind();
            MasterGrid.DataBind();
            FormView1.Visible = false;
            Save.Visible = false;
            Cancel.Visible = false;
          
        }



        protected void MasterGrid_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            Save.Visible = true;
            Cancel.Visible = true;
            
        }

        protected void Cancel_Click1(object sender, EventArgs e)
        {

            FormView1.Visible = false;
            Save.Visible = false;
            Cancel.Visible = false;
        }

        protected void MasterGrid_DataBound(object sender, EventArgs e)
        {
            object user = Session["IsAdmin"];

            if (user == null)
                MasterGrid.Columns[0].Visible = false;
        }


   

     


       
    }
}